/**
 * 
 */
package sailing.excel.translators;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

import sailing.entity.LoanAccount;
import sailing.excel.TranslationException;
import sailing.excel.Translator;
import cjlite.logger.Logger;

/**
 * @author kevin
 * 
 */
public class LoanAccountTranslator extends Translator<LoanAccount> {
	private static Logger logger = Logger.thisClass();

	@Override
	public void fromRow(LoanAccount t, Row row) throws TranslationException {
		parseRow(row);

	}

	@Override
	public void toRow(LoanAccount t, Row row) throws TranslationException {

	}

	@Override
	public boolean wouldParse(int rowNum) {
		logger.trace("would parse row ={0}", rowNum);
		return rowNum >= 6;
	}

	private void parseRow(Row row) {
		logger.trace("getFirstCellNum={0}", row.getFirstCellNum());
		logger.trace("getLastCellNum={0}", row.getLastCellNum());
		logger.trace("getPhysicalNumberOfCells={0}", row.getPhysicalNumberOfCells());

		int startC = row.getFirstCellNum();
		int endC = row.getLastCellNum();

		StringBuilder sb = new StringBuilder();
		for (int c = startC; c < endC; c++) {
			Cell cell = row.getCell(c);
			if (cell != null) {
				// sb.append(cell.getCellType());
				sb.append(getCellValue(cell));
				sb.append('\t');
				
			}
		}
		sb.append('\n');

		logger.logString(sb.toString());

	}



}
